{{csrf_field()}}
<input type="hidden" name="type"  value="{{request()->input('type','')}}">
<div class="layui-row">
    <div class="layui-col-md12">

        <div class="layui-form-item">
            <label class="layui-form-label">父分类</label>
            <div class="layui-input-block">
                <select name="parent_id">
                    <option value="0">请选择父分类</option>
                    @foreach($categorys as $key =>$val)
                    <option value="{{$val['id']}}" @if((isset($info->id) && ($val['id'] == $info->parent_id)) || (isset($id) && $val['id']==$id)) selected="selected" @endif>{{$val['cat_name']}}</option>
                    @endforeach

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" id="title" value="{{$info->title?? old('title')}}" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">分类别名</label>
            <div class="layui-input-block">
                <input type="text" name="slug" id="slug" value="{{$info->slug??  old('slug')}}"  autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        @if($type =='goods')
        <div class="layui-form-item">
            <label class="layui-form-label">所属类型</label>
            <div class="layui-input-block">
                <select >


                </select>
            </div>
        </div>
        @endif
        <div class="layui-form-item">
            <label class="layui-form-label ">图片：</label>
            <div class="layui-input-block">
                <button type="button"  class="layui-btn upload-image">上传图片</button>
                <div class="layui-upload-list">

                    @if(isset($info->logo) && !empty($info->logo))
                        <img class="layui-upload-img" src="{{$info->thumb?? ''}}" style="width: 90px" >
                    @else
                        <img class="layui-upload-img" style="width: 90px" >
                    @endif
                    <input type="hidden" name="thumb" value="{{$info->thumb?? ''}}">
                </div>

            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">

                <textarea name="content" placeholder="请输入内容" class="layui-textarea">{{$config->content?? old('content')}}</textarea>

            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">SEO 标题</label>
            <div class="layui-input-block">
                <input type="text" name="meta_title" value="{{$info->meta_title??  old('meta_title')}}"  autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">SEO 关键字</label>
            <div class="layui-input-block">
                <input type="text" name="meta_keywords" value="{{$info->meta_keywords?? old('meta_keywords')}}" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">SEO 描述</label>
            <div class="layui-input-block">
                <textarea name="meta_description" placeholder="请输入内容" class="layui-textarea">{{$info->meta_description??''}}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="config" lay-submit>保 存</button>
                <button class="layui-btn layui-btn-primary" type="reset">重 置</button>

            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                @if ($errors->any())
                    @foreach ($errors->all() as $error)
                        <p>{{ $error }}</p>
                    @endforeach
                @endif
            </div>
        </div>


    </div>

</div>
<textarea id="edit_image" style="display: none;"></textarea>
@section('script')
    <script>
        layui.use(['layer', 'form','jquery','strpy'], function(){
            var layer = layui.layer,
                $  = layui.jquery;

            var _editor = UE.getEditor("edit_image",{
                initialFrameWidth:800,
                initialFrameHeight:300,
                zIndex:19891026,
            });
            _editor.ready(function (){
                _editor.hide();
                _editor.addListener('beforeInsertImage',function(t,arg){
                    console.log(arg);
                    console.log(t);
                    var obj = _editor.queryCommandValue("serverparam");
                    if(obj.type == "upload-image"){
                        if(arg.length>1){
                            layer.msg("最多只能选择1张图片，请重新选择");
                            return false;
                        }
                        if(arg.length>0) {
                            var uploadImageTd = obj.uploadImageItem.parent().find(".layui-upload-list");
                            console.log(uploadImageTd);
                            uploadImageTd.find('img').attr('src',arg[0].src);
                            uploadImageTd.find('input').val(arg[0].image_id);
                            uploadImageTd.show();
                        }else{
                            layer.msg("请先选择图片");
                            return false;
                        }
                    }
                    return true;
                });
            });

            $("body").on("click", ".upload-image", function () {

                //此处进行初始化
                var obj = _editor.queryCommandValue("serverparam");
                obj.type = "upload-image";
                obj.uploadImageItem = $(this);
                var uploadImage = _editor.getDialog("insertimage");
                console.log(obj);
                uploadImage.open();
            });

            $("#title, #slug").change(function(){
                var strpy= layui.strpy($(this).val(),'-');
                $('#slug').val(strpy.replace(/\ /g, "-"));
            });

        });
    </script>
@endsection
